//--------------------------------------- NOTES ------------------------------------------------------//
* This table is Table A11 in the paper 
//--------------------------------------------------------------------------------------------------------//

cd  "/YOUR_LOCAL_DIRECTORY" //setting the working directory
clear all //remove all data, labels, matrices etc (incl. Mata functions)
use game_state_pilot_data.dta, clear

* Create the key treatment variable
gen byte status_quo = treatment=="status_quo"
la var status_quo  "Status Quo"

* Create Y variable
****** How many balls are used?
gen ballsused = 0
replace ballsused = 1 if player2action=="MixWithLowBlue"
replace ballsused = 1 if player2action=="MixWithHighBlue"

****** Transplant number calculation
gen byte transplanted = player2action=="MixWithLowBlue" | player2action=="MixWithHighBlue" 

** Transplant rate
gen transplant_rate = transplanted

* Did the TC made the patient worse? - a jar that is worse than an urn is mixed into urn
gen byte madeworse = player1bluecount<player2lowbluecount & player2action=="MixWithLowBlue" 
replace madeworse =1 if player1bluecount<player2highbluecount & player2action=="MixWithHighBlue"
replace madeworse =. if player1action!="Offer" 
replace madeworse =. if player2action=="RejectOffer" 

** make worse rate
gen makeworse_rate = madeworse/transplanted

* Make table (components)

* Make table (Pilot 1)

eststo clear

eststo: quietly reg transplant_rate status_quo if pilot==1,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg transplant_rate status_quo player1bluecount if pilot==1,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg transplant_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==1,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

eststo: quietly reg makeworse_rate status_quo if pilot==1,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg makeworse_rate status_quo player1bluecount if pilot==1,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg makeworse_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==1,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

esttab using table_transplants_final_pilot1_a11.tex, se r2  keep(status_quo player1bluecount player2highbluecount player2lowbluecount _cons) star(+ 0.1 * 0.05 ** 0.01)

* Make table (Pilot 2)

eststo clear

eststo: quietly reg transplant_rate status_quo if pilot==2,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg transplant_rate status_quo player1bluecount if pilot==2,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg transplant_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==2,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

eststo: quietly reg makeworse_rate status_quo if pilot==2,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg makeworse_rate status_quo player1bluecount if pilot==2,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg makeworse_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==2,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

esttab using table_transplants_final_pilot2_a11.tex, se r2  keep(status_quo player1bluecount player2highbluecount player2lowbluecount _cons) star(+ 0.1 * 0.05 ** 0.01)

* Make table (Pilot 3)

eststo clear

eststo: quietly reg transplant_rate status_quo if pilot==3,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg transplant_rate status_quo player1bluecount if pilot==3,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg transplant_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==3,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

eststo: quietly reg makeworse_rate status_quo if pilot==3,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg makeworse_rate status_quo player1bluecount if pilot==3,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg makeworse_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==3,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

esttab using table_transplants_final_pilot3_a11.tex, se r2  keep(status_quo player1bluecount player2highbluecount player2lowbluecount _cons) star(+ 0.1 * 0.05 ** 0.01)

* Make table (Pilot 4)

eststo clear

eststo: quietly reg transplant_rate status_quo if pilot==4,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg transplant_rate status_quo player1bluecount if pilot==4,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg transplant_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==4,  vce(cluster room) // Compare kidney transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

eststo: quietly reg makeworse_rate status_quo if pilot==4,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group
eststo: quietly reg makeworse_rate status_quo player1bluecount if pilot==4,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar quality
eststo: quietly reg makeworse_rate status_quo player1bluecount player2highbluecount player2lowbluecount if pilot==4,  vce(cluster room) // (Conditional on TX) Compare kidney BAD transplant rate (jar acceptance rate) by treatment group, controlling for jar and urn qualities

esttab using table_transplants_final_pilot4_a11.tex, se r2  keep(status_quo player1bluecount player2highbluecount player2lowbluecount _cons) star(+ 0.1 * 0.05 ** 0.01)
